<?php

/**
 * This is the model class for table "mv_object".
 *
 * The followings are the available columns in table 'mv_object':
 * @property integer $id
 * @property string $title
 * @property string $bigimg
 * @property string $smallimg
 * @property string $description
 * @property string $actor
 * @property integer $category_id
 * @property integer $showtime
 * @property integer $dateline
 * @property string $status
 * @property integer $click
 * @property integer $recommend
 *
 * The followings are the available model relations:
 * @property MvCategory $category
 * @property MvResource[] $mvResources
 */
class MvObject extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return MvObject the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mv_object';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title, bigimg, smallimg, description, actor, category_id, status', 'required'),
			array('category_id, showtime, dateline, click, recommend', 'numerical', 'integerOnly'=>true),
			array('title, bigimg, smallimg', 'length', 'max'=>255),
			array('actor', 'length', 'max'=>50),
			array('status', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, title, bigimg, smallimg, description, actor, category_id, showtime, dateline, status, click, recommend', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
			'resources' => array(self::HAS_MANY, 'Resource', 'object_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Title',
			'bigimg' => 'Bigimg',
			'smallimg' => 'Smallimg',
			'description' => 'Description',
			'actor' => 'Actor',
			'category_id' => 'Category',
			'showtime' => 'Showtime',
			'dateline' => 'Dateline',
			'status' => 'Status',
			'click' => 'Click',
			'recommend' => 'Recommend',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('bigimg',$this->bigimg,true);
		$criteria->compare('smallimg',$this->smallimg,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('actor',$this->actor,true);
		$criteria->compare('category_id',$this->category_id);
		$criteria->compare('showtime',$this->showtime);
		$criteria->compare('dateline',$this->dateline);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('click',$this->click);
		$criteria->compare('recommend',$this->recommend);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}